package com.haixiaoke.flat.apartment.controller;

import com.haixiaoke.auth.AuthCheck;
import com.haixiaoke.saas.apartment.domain.CalendarPrice;
import com.haixiaoke.saas.apartment.service.ICalendarPriceService;
import com.haixiaoke.saas.apartment.service.IHousingAllocationService;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 价格日历Controller
 *
 * @Author panda
 * @Date 2024/4/10
 **/
@RestController
@RequestMapping("/front/apartment/calendarPrice")
public class FlatCalendarPriceController extends BaseController {

    @Autowired
    private ICalendarPriceService calendarPriceService;
    @Autowired
    private IHousingAllocationService housingAllocationService;

    /**
     * 获取指定时间范围的每日价格
     * @param calendarPrice
     * @return
     */
    @PostMapping("/getPriceList")
    public AjaxResult getPriceList(@RequestBody CalendarPrice calendarPrice){
        if (calendarPrice.getStartTime() == null || calendarPrice.getEndTime() == null) {
            return warn("请选择时间");
        }
        if (calendarPrice.getStartTime().after(calendarPrice.getEndTime())) {
            return warn("时间格式错误");
        }
        if (housingAllocationService.checkTimeRange(calendarPrice.getHouseId(),calendarPrice.getEndTime())){
            return error("该房屋已超过预定范围时间");
        }
        List<CalendarPrice> calendarPriceList = calendarPriceService.getPriceList(calendarPrice);
        return success(calendarPriceList);
    }
}
